using EnvDTE;
using System;
using System.Runtime.InteropServices;

namespace AvaloniaMaidVSIX.Models
{

    public class SelectionProjectItemInfo : ProjectItemInfo, IDisposable
    {
        public int SelectionStartIndex { get; set; }
        public int SelectionEndIndex { get; set; }
        public string SelectionText { get; set; }
        public TextSelection TextSelection { get; set; }

        public SelectionProjectItemInfo()
        {

        }

        public SelectionProjectItemInfo(string projectPath, string itemPath) : base(projectPath, itemPath)
        {

        }
        public void DeleteSelection()
        {
            TextSelection.Delete();
        }

        public void UpdateSelection(string newCode)
        {
            TextSelection.Delete();
            TextSelection.Insert(newCode);
        }

        public void Dispose()
        {
            if (TextSelection is null) return;
            Marshal.ReleaseComObject(TextSelection);
            TextSelection = null;
        }
    }
}
